package com.ruan.controller;

import com.ruan.dto.LoginDto;
import com.ruan.entity.R;
import com.ruan.entity.User;
import com.ruan.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @ClassName:LoginController
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/9/20 15:25
 **/
@Api(tags = "用户登陆，注册相关接口")
@RestController
public class LoginController {


    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户注册")
    @ApiImplicitParam(name = "user",value = "用户信息",required = true,dataType = "User")
    @PostMapping("/register")
    public R<Void> register(@Valid @RequestBody User user){
        return userService.register(user);
    }

    @ApiOperation(value = "用户登陆")
    @ApiImplicitParam(name = "loginDto",value = "用户登陆信息",required = true,dataType = "LoginDto")
    @PostMapping("/login")
    public R<Map<String,String>> login(@Valid @RequestBody LoginDto loginDto){
        return userService.login(loginDto);
    }

    @GetMapping("/activation")
    @ApiOperation(value = "用户邮箱激活")
    @ApiImplicitParam(name = "token",value = "激活码",required = true,dataType = "String")
    public R<Void> activation(String token){
        return userService.activation(token);
    }

    @PostMapping("/logout")
    @ApiOperation(value = "退出登陆")
    public R<Void> logout(){
        return userService.logout();
    }
}
